import {Component, OnInit} from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {ActivatedRoute} from '@angular/router';

@Component({
  selector: 'app-person-detail',
  templateUrl: './person-detail.component.html',
  styleUrls: ['./person-detail.component.css']
})
export class PersonDetailComponent implements OnInit {
  person: object;
  personTab = 0;
  relevanceMovies: any;

  constructor(private http: HttpClient, private activatedRoute: ActivatedRoute) {
    const id = this.activatedRoute.snapshot.params['id'];
    if (id !== undefined && id !== '0') {
      this.http.get(`/person/detail/${id}`).subscribe(result => {
        this.person = result;
        const name = result['name'];
        this.http.get(`/movie/findByPersonName?actor=${name}&director=${name}`).subscribe(data => this.relevanceMovies = data);
      });
    }
  }

  ngOnInit() {
  }

}
